<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="100px">
      <el-form-item label="Fee No" prop="feeNo">
        <el-input
          style="width: 200px;"
          v-model="queryParams.feeNo"
          placeholder=""
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="Client Name" prop="clientName">
        <el-input
          style="width: 200px;"
          v-model="queryParams.clientName"
          placeholder=""
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <!--<el-form-item label="${comment}" prop="contactPerson">-->
        <!--<el-input-->
          <!--v-model="queryParams.contactPerson"-->
          <!--placeholder="请输入${comment}"-->
          <!--clearable-->
          <!--@keyup.enter.native="handleQuery"-->
        <!--/>-->
      <!--</el-form-item>-->
      <!--<el-form-item label="${comment}" prop="canname">-->
        <!--<el-input-->
          <!--v-model="queryParams.canname"-->
          <!--placeholder="请输入${comment}"-->
          <!--clearable-->
          <!--@keyup.enter.native="handleQuery"-->
        <!--/>-->
      <!--</el-form-item>-->
      <el-form-item label="Position Title" prop="positionTitle">
        <el-input
          style="width: 200px;"
          v-model="queryParams.positionTitle"
          placeholder=""
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="Paid Date" prop="reportDate">
        <el-date-picker
          style="width: 150px;"
          clearable
          v-model="queryParams.startTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="startTime">
        </el-date-picker>
        <span style="margin-left: 10px;margin-right: 10px;">-</span>
        <el-date-picker
          style="width: 150px;"
          clearable
          v-model="queryParams.endTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="endTime">
        </el-date-picker>
      </el-form-item>
      <!--<el-form-item label="${comment}" prop="feePercent">-->
        <!--<el-input-->
          <!--v-model="queryParams.feePercent"-->
          <!--placeholder="请输入${comment}"-->
          <!--clearable-->
          <!--@keyup.enter.native="handleQuery"-->
        <!--/>-->
      <!--</el-form-item>-->
      <!--<el-form-item label="${comment}" prop="endOfGuDate">-->
        <!--<el-date-picker clearable-->
          <!--v-model="queryParams.endOfGuDate"-->
          <!--type="date"-->
          <!--value-format="yyyy-MM-dd"-->
          <!--placeholder="请选择${comment}">-->
        <!--</el-date-picker>-->
      <!--</el-form-item>-->
      <!--<el-form-item label="${comment}" prop="feeAmt">-->
        <!--<el-input-->
          <!--v-model="queryParams.feeAmt"-->
          <!--placeholder="请输入${comment}"-->
          <!--clearable-->
          <!--@keyup.enter.native="handleQuery"-->
        <!--/>-->
      <!--</el-form-item>-->
      <!--<el-form-item label="${comment}" prop="createUserId">-->
        <!--<el-input-->
          <!--v-model="queryParams.createUserId"-->
          <!--placeholder="请输入${comment}"-->
          <!--clearable-->
          <!--@keyup.enter.native="handleQuery"-->
        <!--/>-->
      <!--</el-form-item>-->
      <!--<el-form-item label="${comment}" prop="paidDate">-->
        <!--<el-date-picker clearable-->
          <!--v-model="queryParams.paidDate"-->
          <!--type="date"-->
          <!--value-format="yyyy-MM-dd"-->
          <!--placeholder="请选择${comment}">-->
        <!--</el-date-picker>-->
      <!--</el-form-item>-->
      <!--<el-form-item label="${comment}" prop="finalsalary">-->
        <!--<el-input-->
          <!--v-model="queryParams.finalsalary"-->
          <!--placeholder="请输入${comment}"-->
          <!--clearable-->
          <!--@keyup.enter.native="handleQuery"-->
        <!--/>-->
      <!--</el-form-item>-->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">Search</el-button>
        <!--<el-button v-if="false" icon="el-icon-refresh" size="mini" @click="resetQuery">Reset</el-button>-->
      </el-form-item>
    </el-form>

    <!--<el-row :gutter="10" class="mb8">-->
      <!--<el-col :span="1.5">-->
        <!--<el-button-->
          <!--type="primary"-->
          <!--plain-->
          <!--icon="el-icon-plus"-->
          <!--size="mini"-->
          <!--@click="handleAdd"-->
          <!--v-hasPermi="['system:note:add']"-->
        <!--&gt;新增</el-button>-->
      <!--</el-col>-->
      <!--<el-col :span="1.5">-->
        <!--<el-button-->
          <!--type="success"-->
          <!--plain-->
          <!--icon="el-icon-edit"-->
          <!--size="mini"-->
          <!--:disabled="single"-->
          <!--@click="handleUpdate"-->
          <!--v-hasPermi="['system:note:edit']"-->
        <!--&gt;修改</el-button>-->
      <!--</el-col>-->
      <!--<el-col :span="1.5">-->
        <!--<el-button-->
          <!--type="danger"-->
          <!--plain-->
          <!--icon="el-icon-delete"-->
          <!--size="mini"-->
          <!--:disabled="multiple"-->
          <!--@click="handleDelete"-->
          <!--v-hasPermi="['system:note:remove']"-->
        <!--&gt;删除</el-button>-->
      <!--</el-col>-->
      <!--<el-col :span="1.5">-->
        <!--<el-button-->
          <!--type="warning"-->
          <!--plain-->
          <!--icon="el-icon-download"-->
          <!--size="mini"-->
          <!--@click="handleExport"-->
          <!--v-hasPermi="['system:note:export']"-->
        <!--&gt;导出</el-button>-->
      <!--</el-col>-->
      <!--<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>-->
    <!--</el-row>-->

    <el-table
      border
      v-loading="loading"
      :data="noteList"
      @selection-change="handleSelectionChange">
      <el-table-column width="70px" label="Action" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
          >Edit</el-button>
          <!--<el-button-->
          <!--size="mini"-->
          <!--type="text"-->
          <!--icon="el-icon-delete"-->
          <!--@click="handleDelete(scope.row)"-->
          <!--&gt;删除</el-button>-->
        </template>
      </el-table-column>
      <el-table-column
        label="Invoice Date"
        align="left"
        prop="checkDate"
        width="100">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.checkDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column width="100px" prop="status" label="Status">
        <template scope="scope">
          <span style="color: red;font-weight: bold;">{{scope.row.status}}</span>
        </template>
      </el-table-column>
      <el-table-column label="Fee No" align="left" prop="feeNo" />
      <el-table-column label="Client Name" align="left" prop="clientName" />
      <el-table-column label="Position Title" align="left" prop="positionTitle" />
      <el-table-column label="Amount" align="left" prop="amount" />
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { listNote, getNote, delNote, addNote, updateNote } from "@/api/system/note";

export default {
  name: "Note",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 【请填写功能名称】表格数据
      noteList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        clientId: null,
        feeNo: null,
        clientName: null,
        addressLine1: null,
        addressLine2: null,
        contactPerson: null,
        canname: null,
        positionTitle: null,
        reportDate: null,
        startTime: null,
        endTime: null,
        feePercent: null,
        endOfGuDate: null,
        feeAmt: null,
        status: null,
        createUserId: null,
        paidDate: null,
        finalsalary: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询【请填写功能名称】列表 */
    getList() {
      this.loading = true;
      listNote(this.queryParams).then(response => {
        this.noteList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        clientId: null,
        feeNo: null,
        clientName: null,
        addressLine1: null,
        addressLine2: null,
        contactPerson: null,
        canname: null,
        positionTitle: null,
        reportDate: null,
        feePercent: null,
        endOfGuDate: null,
        feeAmt: null,
        status: null,
        createUserId: null,
        paidDate: null,
        remark: null,
        finalsalary: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加【请填写功能名称】";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      // 关闭指定页签
      const obj = { path: "/system/note/noteAdd", name: "NoteAdd" };
      this.$tab.closePage(obj);
      setTimeout(()=> {
        // 关闭当前tab页签，打开新页签
        const obj = {path:'/system/note/noteAdd',query: {id: row.id, clientId: row.clientId}};
        this.$tab.closeOpenPage(obj);
      }, 300);
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateNote(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addNote(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除？').then(function() {
        return delNote(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/note/export', {
        ...this.queryParams
      }, `note_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
